"""Add is_email_verified field to User model

Revision ID: add_is_email_verified
Revises: 
Create Date: 2023-09-01 00:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'add_is_email_verified'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('user', sa.Column('is_email_verified', sa.Boolean(), nullable=True))
    
    # 设置所有现有用户的is_email_verified为True
    op.execute("UPDATE \"user\" SET is_email_verified = TRUE")
    
    # 将列改为NOT NULL
    op.alter_column('user', 'is_email_verified', nullable=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('user', 'is_email_verified')
    # ### end Alembic commands ### 